﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PIM_ATE.Mods
{
    public partial class FrmDeviceMod : Form
    {
        public FrmDeviceMod()
        {
            InitializeComponent();
            this.ControlBox = false;
        }

        JcPIMInstrumentInfo m_device;

        private void FormDeviceMod_Load(object sender, EventArgs e)
        {
            var lstBandName = new List<string>();
            foreach (var band in JcPIMDevicesBuilder.dicBands)
            {
                lstBandName.Add(band.Value.range_alias);
            }

            comboType.Items.AddRange(lstBandName.ToArray());

            IniFile.SetFileName(Application.StartupPath + "\\JcDevices.ini");
            string section = "Desktop_Config";
            comboType.Text = IniFile.IniReadValue(section, "Device1_Band", "0");
            textAddress.Text = IniFile.IniReadValue(section, "Device1_IP", "");      
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            JcPIMDevicesBuilder.dicDevices.Clear();
            var dev = new JcPIMInstrumentInfo(true, comboType.Text, textAddress.Text, Instrument.DESKTOP_FOR_1REV);
            dev.instrBandName = JcPIMDevicesBuilder.dicBands[comboType.Text].range_name;
            dev.instrBandIndex = -1;
            dev.instrAddress = textAddress.Text;
            JcPIMDevicesBuilder.dicDevices.Add(dev.instrBandName, dev);

            IniFile.SetFileName(Application.StartupPath + "\\JcDevices.ini");
            string section = "Desktop_Config";
            IniFile.IniWriteValue(section, "Device1_Band", comboType.Text);
            IniFile.IniWriteValue(section, "Device1_IP", textAddress.Text);
            IniFile.IniWriteValue(section, "Device1_Type", "DESKTOP_FOR_1REV");
            IniFile.IniWriteValue(section, "Device1_Enable  ", "1");

            this.DialogResult = DialogResult.OK;
        }
    }
}
